package com.hmall.common.utils;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

@RequiredArgsConstructor
public class RabbitMqHelper {

    private final RabbitTemplate rabbitTemplate;

    public void sendMessage(String exchange, String routingKey, Object msg){
        rabbitTemplate.convertAndSend(exchange, routingKey, msg);
    }

    public void sendDelayMessage(String exchange, String routingKey, Object msg, int delay){
        rabbitTemplate.convertAndSend(exchange, routingKey, msg, message -> {
            message.getMessageProperties().setDelay(delay);
            return message;
        });

    }

    public void sendMessageWithConfirm(String exchange, String routingKey, Object msg, int maxRetries){
       
    }

    public void sendMessageWithMessagePostProcessor(String exchange, String routingKey, Object msg, MessagePostProcessor messagePostProcessor){
        rabbitTemplate.convertAndSend(exchange, routingKey, msg, messagePostProcessor);
    }
}